import 'dart:convert';

import '../helper/Helper.dart';

import '../helper/dioHelper2.dart';


class DayData {
  int ID;
  String TM;
  double AverH1;
  double AverH2;
  double AverH3;
  double AverP;
  double AverR;
  double AverQz;
  double AverQf;
  double AverQp;
  double AverWr;
  double AverWz;
  double AverWf;
  double AverWq;
  int FdHour1;
  int FdHour2;
  int FdHour3;
  int FdHour4;
  double YBR1;
  double YBR2;
  double FdJH;
  double ZFdL;
  double SWDL;
  double MaxFdP;
  double MinFdP;
  double AverFdP;
  double FdFHL;
  double FdHSL;
  double TFSSDL;
  double MaxPNextDay;
  double MaxZPNextDay;
  double ENextDay;
  double H0;
  double KTW0;
  double Z0;
  double XNZ0;
  double YSXQ;
  double MaxR;
  double MinR;
  double MaxQ;
  double MinQ;
  double AverA;

  DayData(
      this.ID,
      this.TM,
      this.AverH1,
      this.AverH2,
      this.AverH3,
      this.AverP,
      this.AverR,
      this.AverQz,
      this.AverQf,
      this.AverQp,
      this.AverWr,
      this.AverWz,
      this.AverWf,
      this.AverWq,
      this.FdHour1,
      this.FdHour2,
      this.FdHour3,
      this.FdHour4,
      this.YBR1,
      this.YBR2,
      this.FdJH,
      this.ZFdL,
      this.SWDL,
      this.MaxFdP,
      this.MinFdP,
      this.AverFdP,
      this.FdFHL,
      this.FdHSL,
      this.TFSSDL,
      this.MaxPNextDay,
      this.MaxZPNextDay,
      this.ENextDay,
      this.H0,
      this.KTW0,
      this.Z0,
      this.XNZ0,
      this.YSXQ,
      this.MaxR,
      this.MinR,
      this.MaxQ,
      this.MinQ,
      this.AverA);
  DayData.fromJson(Map<String, dynamic> json)
      : ID = json["ID"],
        TM = json["TM"],
        AverH1 = json["AverH1"] * 1.0,
        AverH2 = json["AverH2"] * 1.0,
        AverH3 = json["AverH3"] * 1.0,
        AverP = json["AverP"] * 1.0,
        AverR = json["AverR"] * 1.0,
        AverQz = json["AverQz"] * 1.0,
        AverQf = json["AverQf"] * 1.0,
        AverQp = json["AverQp"] * 1.0,
        AverWr = json["AverWr"] * 1.0,
        AverWz = json["AverWz"] * 1.0,
        AverWf = json["AverWf"] * 1.0,
        AverWq = json["AverWq"] * 1.0,
        FdHour1 = json["FdHour1"],
        FdHour2 = json["FdHour2"],
        FdHour3 = json["FdHour3"],
        FdHour4 = json["FdHour4"],
        YBR1 = json["YBR1"] * 1.0,
        YBR2 = json["YBR2"] * 1.0,
        FdJH = json["FdJH"] * 1.0,
        ZFdL = json["ZFdL"] * 1.0,
        SWDL = json["SWDL"] * 1.0,
        MaxFdP = json["MaxFdP"] * 1.0,
        MinFdP = json["MinFdP"] * 1.0,
        AverFdP = json["AverFdP"] * 1.0,
        FdFHL = json["FdFHL"] * 1.0,
        FdHSL = json["FdHSL"] * 1.0,
        TFSSDL = json["TFSSDL"] * 1.0,
        MaxPNextDay = json["MaxPNextDay"] * 1.0,
        MaxZPNextDay = json["MaxZPNextDay"] * 1.0,
        ENextDay = json["ENextDay"] * 1.0,
        H0 = json["H0"] * 1.0,
        KTW0 = json["KTW0"] * 1.0,
        Z0 = json["Z0"] * 1.0,
        XNZ0 = json["XNZ0"] * 1.0,
        YSXQ = json["YSXQ"] * 1.0,
        MaxR = json["MaxR"] * 1.0,
        MinR = json["MinR"] * 1.0,
        MaxQ = json["MaxQ"] * 1.0,
        MinQ = json["MinQ"] * 1.0,
        AverA = json["AverA"] * 1.0;
  Map<String, dynamic> toJson() => {
        'ID': ID,
        'TM': TM,
        'AverH1': AverH1,
        'AverH2': AverH2,
        'AverH3': AverH3,
        'AverP': AverP,
        'AverR': AverR,
        'AverQz': AverQz,
        'AverQf': AverQf,
        'AverQp': AverQp,
        'AverWr': AverWr,
        'AverWz': AverWz,
        'AverWf': AverWf,
        'AverWq': AverWq,
        'FdHour1': FdHour1,
        'FdHour2': FdHour2,
        'FdHour3': FdHour3,
        'FdHour4': FdHour4,
        'YBR1': YBR1,
        'YBR2': YBR2,
        'FdJH': FdJH,
        'ZFdL': ZFdL,
        'SWDL': SWDL,
        'MaxFdP': MaxFdP,
        'MinFdP': MinFdP,
        'AverFdP': AverFdP,
        'FdFHL': FdFHL,
        'FdHSL': FdHSL,
        'TFSSDL': TFSSDL,
        'MaxPNextDay': MaxPNextDay,
        'MaxZPNextDay': MaxZPNextDay,
        'ENextDay': ENextDay,
        'H0': H0,
        'KTW0': KTW0,
        'Z0': Z0,
        'XNZ0': XNZ0,
        'YSXQ': YSXQ,
        'MaxR': MaxR,
        'MinR': MinR,
        'MaxQ': MaxQ,
        'MinQ': MinQ,
        'AverA': AverA,
      };
  static Future<bool> Add(DayData x1) async {
    var response = await DioHelper.Post("/DayData/Add", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Update(DayData x1) async {
    var response = await DioHelper.Post("/DayData/Update", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<bool> Delete(DayData x1) async {
    var st = x1.toJson();
    var response = await DioHelper.Post("/DayData/Delete", x1.toJson());
    if (response.statusCode == 200) return true;
    return false;
  }

  static Future<DayData?> Get(String where, dynamic data) async {
    var response = await DioHelper.Post("/DayData/GetByWhere", {
      "Where": where,
      "obj": data,
    });

    if (response.statusCode == 200) return new DayData.fromJson(response.data);
    return null;
  }

  static Future<List<DayData>> GetList(
      String where, dynamic data, int pageIndex, int pageSize) async {
    var response = await DioHelper.Post("/DayData/GetListByWhere", {
      "Where": where,
      "obj": data,
      "PageIndex": pageIndex,
      "PageSize": pageSize,
    });
    var list1 = <DayData>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new DayData.fromJson(x));
      }
    }
    return list1;
  }

  static List<DayData> GetListByValue(dynamic value)  {
    print(value);
    var list1 = <DayData>[];
    
      for (var x in value) {
        list1.add(new DayData.fromJson(x));
      }
    print(list1);
    return list1;
  }

  static Future<List<DayData>> GetAllList() async {
    var response = await DioHelper.Get("/DayData/GetAllList", {});
    var list1 = <DayData>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new DayData.fromJson(x));
      }
    }
    return list1;
  }

     static Future<List<DayData>> GetListByTM(String t1,t2) async {
    var response = await DioHelper.Get("/SdzxData/GetSKDayListByTM?TM1="+t1+"&TM2="+t2, {});
    var list1 = <DayData>[];
    if (response.statusCode == 200) {
      for (var x in response.data) {
        list1.add(new DayData.fromJson(x));
      }
    }
    //print(list1);
    return list1;
  }
}
